var _imgs,_intro={},_about_html="",_technical_html="",_products_json={},_projects_json={},_banner_json={},_dataToLoad = [{
    type:'json', 
    url:'cms/gallery',
    obj: '_imgs'
},{
    type:'html', 
    url:'cms/about', 
    obj: '_about_html'
}, {
    type:'html', 
    url:'cms/technical',
    obj: '_technical_html'
}, {
    type:'json', 
    url:'cms/hero-images',
    obj:'_banner_json'
}, {
    type:'json',
    url:'cms/projects',
    obj:'_projects_json'
},{
    type:'json',
    url:'cms/products',
    obj:'_products_json'
}],_bytesLoaded=0,_bytesToLoad=0,_loadedPercent=0,_bannerImgAdded=false,_URL="";
$(function(){
    if(_URL.length<1&&window.location.hash.length>1){
        _URL=window.location.hash
        }
        $(document).bind("mousemove.loader",onLoaderMouseHandler);
    $("body").css({
        overflow:"hidden",
        width:$(window).width(),
        height:$(window).height()
        });
    $("#intro-image").bind("IMAGEPRELOADER_COMPLETE.INTRO",_intro.imagesLoaded);
    $("#intro-image").bind("IMAGEPRELOADER_LOADED.INTRO",onElementLoaded);
    var a=(_URL.length===0)?["img/logo.png","img/intro-image.jpg"]:["img/logo.png"];
    _bytesToLoad=a.length+_dataToLoad.length+(_URL.length>1?0:9);
    $("#intro-image").imagePreloader("INTRO",a,"MODE_QUEUED");
    $(window).bind("b",onElementLoaded);
    $("head").getData(_dataToLoad,function(c){
        var d=0,b=c.length;
        for(d;d<b;d++){
            if(c[d].type==="js"){
                $("head").append(c[d].data)
                }else{
                if(c[d].type==="json"){
                    this[c[d].obj+""]=jsonParse(c[d].data)
                    }else{
                    if(c[d].type==="html"){
                        this[c[d].obj+""]=unescape(c[d].data)
                        }
                    }
            }
        }
    onElementLoaded.call(window)
    })
});
onLoaderMouseHandler=function(a){
    $("div#preloader").stop(true).animate({
        top:a.clientY+"px",
        left:a.clientX+"px"
        },550,"easeOutExpo")
    };
    
onElementLoaded=function(){
    _loadedPercent=Math.floor(_bytesLoaded++/_bytesToLoad*100);
    if(!_bannerImgAdded&&_banner_json.length>1){
        _bannerImgAdded=true;
        var c=[];
        for(var b in _banner_json){
            for(var a in _banner_json[b]){
                c.push(_banner_json[b][a].bwImage)
                }
            }
            $("div#preloader").bind("IMAGEPRELOADER_COMPLETE.PRELOADER",onElementLoaded);
    $("div#preloader").bind("IMAGEPRELOADER_LOADED.PRELOADER",onElementLoaded);
    $("div#preloader").imagePreloader("PRELOADER",c,"MODE_QUEUED")
    }
    if(_loadedPercent<100){
    $("div#preloader img").first().stop(true).animate({
        top:Math.floor(_loadedPercent/10)*-55
        },550);
    $("div#preloader img").eq("1").stop(true).animate({
        top:Math.round((_loadedPercent/10-Math.floor(_loadedPercent/10))*10)*-55
        },550)
    }else{
    $("div#preloader img").first().stop(true).animate({
        top:9*-55
    },550);
    $("div#preloader img").eq("1").stop(true).animate({
        top:9*-55
    },550,function(){
        $("div#preloader").stop(true).animate({
            opacity:0
        },440,function(){
            $(this).css("display","none")
            });
        $("#intro-image").css({
            opacity:0,
            visibility:"visible",
            left:($(window).width()-$("#intro-image").width())/2
            }).delay(250).animate({
            opacity:1
        },440,"easeInExpo",function(){
            $(this).css({
                filter:"none"
            });
            onInit()
            });
        $("#nav-wrapper nav div#menu-logo").css({
            opacity:0,
            visibility:"visible"
        }).animate({
            opacity:1
        },350,"easeInExpo");
        $(document).unbind("mousemove.loader",onLoaderMouseHandler);
        $("div#preloader").unbind("IMAGEPRELOADER_COMPLETE.PRELOADER",onElementLoaded);
        $("div#preloader").unbind("IMAGEPRELOADER_LOADED.PRELOADER",onElementLoaded);
        $("div#menu-logo img").animate({
            opacity:1
        },1000)
        })
    }
};

_intro.imagesLoaded=function(b,a){
    onElementLoaded();
    if(a.length>1){
        $("#intro-image").append("<img src='"+a[1][1]+"' alt='intro-image'>").css({
            visibility:((_loadedPercent<100)?"hidden":"visible")
            });
        $("#nav-wrapper nav div#menu-logo").prepend("<img src='"+a[0][1]+"' alt='intro-image'>").css({
            visibility:((_loadedPercent<100)?"hidden":"visible")
            })
        }else{
        $("<img src='"+a[0][1]+"' alt='intro-image'>").prependTo("#nav-wrapper nav div#menu-logo").css({
            opacity:0
        })
        }
        $("#intro-image").unbind("IMAGEPRELOADER_COMPLETE.INTRO",_intro.imagesLoaded);
    $("#intro-image").unbind("IMAGEPRELOADER_LOADED.INTRO",onElementLoaded.call(window))
    };